package com.tianji.learning.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tianji.learning.domain.po.PointsBoardSeason;
import com.tianji.learning.mapper.PointsBoardSeasonMapper;
import com.tianji.learning.service.IPointsBoardSeasonService;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.Optional;

/**
 * <p>
 * 赛季信息表 服务实现类
 * </p>
 *
 * @author yangyu
 * @since 2023-07-29
 */
@Service
public class PointsBoardSeasonServiceImpl extends ServiceImpl<PointsBoardSeasonMapper, PointsBoardSeason> implements IPointsBoardSeasonService {

    /**
     * 根据时间范围，拿到赛季id
     *
     * @param time 时间
     * @return 赛季id
     */
    @Override
    public Integer querySeasonByTime(LocalDateTime time) {
        //time：2023-8-1
        //Optional：如果结果为null，则返回空对象
        Optional<PointsBoardSeason> optional = lambdaQuery()
                //赛季开始时间：<= 2023-8-1
                .le(PointsBoardSeason::getBeginTime, time)
                //赛季结束赛季：>= 2023-8-1
                .ge(PointsBoardSeason::getEndTime, time)
                .oneOpt();
        //orElse（）：如果为id存在那么返回，不存在则返回指定值
        return optional.map(PointsBoardSeason::getId).orElse(null);
    }
}
